import urllib.request

# 适用的场景：数据采集的时候 需要绕过登陆 然后进入到某个页面
# 个人信息页面是utf-8  但是还报错了编码错误  因为并没有进入到个人信息页面 而是跳转到了登陆页面
# 那么登陆页面不是utf-8  所以报错

# 什么情况下访问不成功？
# 因为请求头的信息不够  所以访问不成功
url = 'https://weibo.com/u/6489826480'

headers = {
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'accept-Language': 'zh-CN,zh;q=0.9',
    'cache-Control': 'max-age=0',
    'cookie': 'SINAGLOBAL=2252251366457.523.1594052087772; XSRF-TOKEN=MFYJ2wwnVmcbB61V4MCVBxW8; login_sid_t=5a3fc9c469fbad5ffda97b91b38cc2e6; cross_origin_proto=SSL; wb_view_log=1536*8641.25; _s_tentry=weibo.com; Apache=1079486112965.34.1705540218221; ULV=1705540218227:1:1:1:1079486112965.34.1705540218221:; appkey=; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WF.P2cD.AY-TcPKMap15YxO5JpX5o275NHD95QcShn41hzcShn7Ws4DqcjMi--NiK.Xi-2Ri--ciKnRi-zNSoBR1KnESoBRe5tt; ALF=1708132335; SSOLoginState=1705540335; SUB=_2A25IrAqgDeRhGeBK41sZ8ijIwzyIHXVrwAJorDV8PUNbktANLUjFkW9NR2INQSMhGqG5TFERLWQ1Fgq_00kq4wiG; PC_TOKEN=88f53b3f59; WB_register_version=2024011809; WBPSESS=NFNJQd0ViuiMIUjghzidCrZmKHGvZDQlqaD0v2-ysPbzAFl-RGPTSb81AjtsTP1daR9pu7B-pihNx4lZMwCMnWZTA_EpAr-pkyXLBkjIR6jvO8T5F3QsL9E9PNZ3lpGspZsYKWe-Gw4zxbUAQxbbgg==',
    'referer': 'https://weibo.com/signup/full_info.php?key=2ZjFlqHrxAAOS-4v-_QugXcYL3GgIG49mC3BjX3JlZ2lzdGVy',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}

request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode('utf-8')

print(content)
